@echo on
set BASE-DIR=%SystemDrive%\SERVICE.MAXIT
set HTTPGET=%BASE-DIR%\SYSTEM\wget -t 3 -w 3 --no-cache --ignore-case --no-dns-cache --quiet
set LOGFILE="%BASE-DIR%\LOG\init-maxitservice.log"

echo *** Checking for necessary files ***
if not exist 7za.exe goto ERROR_MISSING_FILES
if not exist wget.exe goto ERROR_MISSING_FILES
echo *** - Check OK

echo *** Creating directory structure ***
mkdir "%BASE-DIR%"
mkdir "%BASE-DIR%\TEMP"
mkdir "%BASE-DIR%\LOG"
mkdir "%BASE-DIR%\KONFIG"
mkdir "%BASE-DIR%\PROGRAMS"
mkdir "%BASE-DIR%\SCRIPTS"
mkdir "%BASE-DIR%\SETUPS"
mkdir "%BASE-DIR%\SYSTEM"

echo *** Copying base files ***
copy 7za.exe "%BASE-DIR%\SYSTEM\" >> %LOGFILE%
copy wget.exe "%BASE-DIR%\SYSTEM\" >> %LOGFILE%

rem ***** change partition
%SystemDrive%

echo *** Downloading SysInternals Tools ***
mkdir "%BASE-DIR%\PROGRAMS\SYSINTERNALS" >> %LOGFILE%
cd "%BASE-DIR%\PROGRAMS\SYSINTERNALS" >> %LOGFILE%
%HTTPGET% http://live.sysinternals.com/procexp.exe >> %LOGFILE%
%HTTPGET% http://live.sysinternals.com/autoruns.exe >> %LOGFILE%
%HTTPGET% http://live.sysinternals.com/Bginfo.exe >> %LOGFILE%
%HTTPGET% http://live.sysinternals.com/Autologon.exe >> %LOGFILE%
%HTTPGET% http://live.sysinternals.com/Tcpview.exe >> %LOGFILE%

echo *** Downloading CAD Utils Pack ***
mkdir "%BASE-DIR%\PROGRAMS\CAD-UTILS" >> %LOGFILE%
cd "%BASE-DIR%\PROGRAMS\CAD-UTILS" >> %LOGFILE%
%HTTPGET% http://www.ctrl-alt-del.com.au/files/CAD_UtilPack.zip >> %LOGFILE%
"%BASE-DIR%\SYSTEM\7za" e -y CAD_UtilPack.zip >> %LOGFILE%
del /q CAD_UtilPack.zip >> %LOGFILE%
%BASE-DIR%\SYSTEM\7za e -y *.zip >> %LOGFILE%
del /q *.zip >> %LOGFILE%

echo *** Downloading Nirsoft CMD ***
cd %BASE-DIR%\SYSTEM
%HTTPGET% http://www.nirsoft.net/utils/nircmd.zip >> %LOGFILE%
"%BASE-DIR%\SYSTEM\7za" e -y nircmd.zip >> %LOGFILE%
del /q nircmd.zip >> %LOGFILE%

echo *** Downloading Kitty (putty replacement) ***
%HTTPGET% http://www.9bis.net/kitty/?file=kitty_portable.exe >> %LOGFILE%
ren "index.html@file=kitty_portable.exe" kitty.exe >> %LOGFILE%

echo *** Downloading fping ***
%HTTPGET% http://www.kwakkelflap.com/files/fping222.zip >> %LOGFILE%
"%BASE-DIR%\SYSTEM\7za" e fping222.zip "x64 (64 bit)\fping.exe" >> %LOGFILE%
ren fping.exe fping64.exe >> %LOGFILE%
"%BASE-DIR%\SYSTEM\7za" e fping222.zip "x86 (32 bit)\fping.exe" >> %LOGFILE%
del /q fping222.zip >> %LOGFILE%

echo *** Downloading wol.exe (Wake-On-Lan Tool) ***
%HTTPGET% http://www.gammadyne.com/wol.exe >> %LOGFILE%

echo *** Downloading MTail ***
%HTTPGET% http://ophilipp.free.fr/soft/mtail.zip >> %LOGFILE%
"%BASE-DIR%\SYSTEM\7za" e -y mtail.zip >> %LOGFILE%
del /q mtail.zip >> %LOGFILE%

echo *** Downloading TFTP2 ***
%HTTPGET% http://www.shadowsoftware.net/shadowgameworld/downloads/tftp2.exe >> %LOGFILE%

echo *** Downlading TeamViewer ***
cd "%BASE-DIR%\PROGRAMS" >> %LOGFILE%
%HTTPGET% http://www.teamviewer.de/download/TeamViewerQS_de.exe >> %LOGFILE%
%BASE-DIR%\SYSTEM\nircmd shortcut "%BASE-DIR%\PROGRAMS\TeamViewerQS_de.exe" "~$folder.common_desktop$" "TeamViewer" >> %LOGFILE%
cd "%BASE-DIR%\SETUPS" >> %LOGFILE%
%HTTPGET% http://www.teamviewer.de/download/TeamViewer_Host_Setup.exe >> %LOGFILE%

echo *** Erstelle Shortcuts ***
%BASE-DIR%\SYSTEM\nircmd execmd mkdir "~$folder.common_programs$\max.it solutions"
if exist "%BASE-DIR%\PROGRAMS\TeamViewerQS_de.exe" %BASE-DIR%\SYSTEM\nircmd shortcut "%BASE-DIR%\PROGRAMS\TeamViewerQS_de.exe" "~$folder.common_desktop$" "TeamViewer
if exist "%BASE-DIR%\PROGRAMS\TeamViewerQS_de.exe" %BASE-DIR%\SYSTEM\nircmd shortcut "%BASE-DIR%\PROGRAMS\TeamViewerQS_de.exe" "~$folder.common_programs$\max.it solutions" "TeamViewer"
if exist "%TVT%\System Update\tvsu.exe" %BASE-DIR%\SYSTEM\nircmd execmd mkdir "~$folder.common_programs$\max.it solutions\Lenovo SystemUpdate"
if exist "%TVT%\System Update\tvsu.exe" %BASE-DIR%\SYSTEM\nircmd shortcut "%TVT%\System Update\tvsu.exe" "~$folder.common_programs$\max.it solutions\Lenovo SystemUpdate" "Suchen und Installieren" "/CM -search R -action INSTALL"
if exist "%TVT%\System Update\tvsu.exe" %BASE-DIR%\SYSTEM\nircmd shortcut "%TVT%\System Update\tvsu.exe" "~$folder.common_programs$\max.it solutions\Lenovo SystemUpdate" "Suchen und Informieren" "/CM -search R -action LIST"
if exist "%TVT%\System Update\tvsu.exe" %BASE-DIR%\SYSTEM\nircmd shortcut "%TVT%\System Update\tvsu.exe" "~$folder.common_programs$\max.it solutions\Lenovo SystemUpdate" "Suchen und Herunterladen" "/CM -search R -action DOWNLOAD"

goto ENDE
:ERROR_MISSING_FILES
echo *** FEHLER ******************************************
echo  Die Dateien 7zipa.exe und wget.exe werden benoetigt
echo  Das Script wird abgebrochen
echo *****************************************************
pause
exit 99
:ENDE

pause